package com.eastseeway.radioproject.calibration;

import androidx.lifecycle.LiveData;

import com.eastseeway.radioproject.RadioApplication;
import com.eastseeway.radioproject.base.BaseRepository;
import com.eastseeway.radioproject.database.RadioProjectDatabase;
import com.eastseeway.radioproject.database.VBusDao;
import com.eastseeway.radioproject.entities.BeanVBus;

import java.util.List;

public class CalibrationRepository extends BaseRepository {
    private final VBusDao mVBusDao;
    public CalibrationRepository() {
        super();
        mVBusDao = RadioProjectDatabase.getInstance(RadioApplication.getInstance()).getVBusDao();
    }

    protected void insertVBusData(BeanVBus beanVBus){
        executorService.submit(()->{
            mVBusDao.insertVBus(beanVBus);
        });
    }

    protected void insertVBusList(List<BeanVBus> beanVBusList){
        executorService.submit(()->{
            mVBusDao.insertVBusList(beanVBusList);
        });
    }

    LiveData<List<BeanVBus>> queryVBusList(String handleType, String freq){
        return mVBusDao.queryVBusByHandleTypeAndFreq(handleType,freq);
    }

    protected void deleteAllVBusData(){
        executorService.submit(()->{mVBusDao.deleteAll();});
    }

    protected void deleteByHandleType(String handleType){
        executorService.submit(()->{
            mVBusDao.deleteByHandleType(handleType);
        });
    }

    LiveData<List<BeanVBus>> queryAllVBus(){
        return mVBusDao.queryAllVBus();
    }
}
